﻿@model List<Model.Order>
<!DOCTYPE html>
<html>
<head>

    <style>
        body {
            font-family: Arial, sans-serif;
        }

        table {
            border-collapse: collapse;
            width: 100%;
        }

        th, td {
            text-align: left;
            padding: 8px;
        }

        tr:nth-child(even) {
            background-color: #f2f2f2;
        }

        th {
            background-color: #4CAF50;
            color: white;
        }
    </style>
    <script src="https://lib.baomitu.com/jquery/3.7.0/jquery.min.js"></script>
</head>
<body>
    <table>
        <tr>
            <th>订单编号</th>
            <th>店铺名</th>
            <th>商品名</th>
            <th>商品数量</th>
            <th>总价格</th>
            <th>下单时间</th>
            <th>订单状态</th>
            <th>操作</th>
        </tr>
        @{
            int i = 0;
            foreach(Model.Order it in Model)
            {
                
                <tr>
                    <td>@it.ID</td>
                    
                    @if(ViewBag.role==3)
                    {
                   
                        <td>@it.customer.Name</td>
                    }
                    @if (ViewBag.role == 2)
                    {
                       <td>@it.ordercommodity![0].commodity.bussiness!.Name</td>
                    }
                    <td>@it.ordercommodity![0].commodity.Name</td>
                    <td>@it.ordercommodity![0].ComNum</td>
                    <td>@it.TotalPrice</td>
                    <td>@it.CreateTime</td>
                    <td>@it.orderState</td>
                    <td>
                    @{
                            <input type="hidden" id="C" value=@it.ordercommodity[0].commodity.ID />
                            <input type="hidden" id="U" value=@it.customer.ID />
                            <iframe width=0 height=0 frameborder=0 id="myiframe" name="myiframe"></iframe>

                            if(ViewBag.role==3)
                            {
                                if (it.orderState == "已付款")
                                {

                                    <form action="/Order/OrderHandle" method="post">
                                    <input type="hidden" name="state" value="已付款">
                                    <input type="hidden" name="oid" value=@it.ID>

                                        <button style="color:orangered" type="submit" onclick="fun3()">发货</button>
                                    </form>
                                }
                                else if (it.orderState == "已发货")
                                {
                                    <button style="color:orangered" onclick="fun2()">提醒收货</button>
                                }
                                else if (it.orderState == "已完成")
                                {
                                    <form action="/Order/deleOrder" method="post">
                                        <input type="hidden" name="state" value="已完成">
                                        <input type="hidden" name="oid" value=@it.ID>

                                        <button style="color:orangered" type="submit" onclick="fun5()">删除</button>
                                    </form>
                                }
                            }
                            else if (ViewBag.role == 2)
                            {
                                if (it.orderState == "已付款")
                                {
                                    <button style="color:orangered" onclick="fun1()">催发货</button>
                                }
                                else if (it.orderState == "已发货")
                                {
                                    <form action="/Order/OrderHandle" method="post">
                                        <input type="hidden" name="state" value="已发货">
                                        <input type="hidden" name="oid" value=@it.ID>

                                        <button style="color:orangered" type="submit" onclick="fun4()">确认收货</button>
                                    </form>
                                }
                                
                                else if (it.orderState == "已完成")
                                {
                                    <form action="/Order/deleOrder" id="com" target="myiframe" method="post">
                                        <input type="hidden" name="state" value="已完成">
                                        <input type="hidden" name="oid" value=@it.ID>
                                        <button style="color:orangered" type="submit" onclick="fun5()">删除</button>
                                    </form>
                                    <form action="/Commodity/CommentInsert" target="myiframe" method="get" name="add" class="successed">
                                        <input type="hidden"  >
                                        <input type="hidden" name="oid" value=@it.ID>
                                        <button style="color:orangered">评价</button>
                                    </form>
                                }
                            }
                            
                            else
                            {
                                <button style="color:orangered">无用户</button>
                            }
                        }</td>
                </tr>
            }
        }
    </table>
    
    <!-- 在这里添加删除和更改订单状态的功能 -->

</body>
<script>
    function fun1()
    { alert('商家已收到提醒！'); }
    function fun2() { alert('用户已收到提醒！'); }
    function fun3(){alert('发货成功！')}
    function fun4() { alert('收货成功！') }
    function fun5() { alert('删除成功！') }
    //function CommentFun()
    //{
    //    var commen=prompt("请输入对该商品的评价：");

    //    document.getElementById("comment").value=commen;
    //    document.getElementById("uid").value = document.getElementById("U").value;
    //    document.getElementById("cid").value = document.getElementById("C").value;
    //    document.getElementById("comdd").submit();
    //    alert('评价成功');      
    //}
    

    let ses = document.querySelectorAll('.successed')
    for(let i=0;i<ses.length;i++){
        console.log(ses[i])
        ses[i].setAttribute("id", "form" + i)

        console.log(ses[i].children[2])

        ses[i].children[2].onclick = function(e){
            e.preventDefault()
            ses[i].children[0].value = prompt("请输入评价内容：")
            ses[i].children[0].setAttribute('name','comment')
            console.log(ses[i].children[0],i)
            ses[i].submit()
            alert('评论成功');
        }
    }


</script>
</html>

